package com.akk.action;

import com.akk.business.AvsHlbQuickBusiness;
import com.akk.module.avs.model.request.*;
import com.akk.utils.RestResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * Created by admin on 2017/11/11.
 * 合利宝快捷
 */
@RestController
@RequestMapping("/thmlfApi/avs/hlbquick")
public class AvsHlbQuickAction {

    @Autowired
    private AvsHlbQuickBusiness hlbQuickBusiness;


    @PostMapping("/createpaynotbind")
    @ApiOperation(value = "选择银行卡发起支付", notes = "选择银行卡（未绑定通道）发起支付", httpMethod = "POST", response = RestResponse.class)
    public RestResponse createPayNotBind(@RequestBody CreatePayNotBindRequest request) {
        return hlbQuickBusiness.createPayNotBind(request);
    }

//    @PostMapping("/paymentNotify")
//    @ApiIgnore
//    public String paymentNotify(HlbPayNotifyRequest request) {
//        return hlbQuickBusiness.paymentNotify(request);
//    }

    @PostMapping(value = "/createpay")
    @ApiOperation(value = "发起支付", notes = "发起支付", httpMethod = "POST", response = RestResponse.class)
    public RestResponse createPay(@RequestBody CreatePayRequest request) {
        return hlbQuickBusiness.createPay(request);
    }

    @PostMapping(value = "/bindcardpay")
    @ApiOperation(value = "绑卡支付", notes = "绑卡支付", httpMethod = "POST", response = RestResponse.class)
    public RestResponse bindCardPay(@RequestBody BindCardPayRequest request) {
        return hlbQuickBusiness.bindCardPay(request);
    }


    @RequestMapping("/sendpaycode")
    @ApiOperation(value = "发送支付验证码", notes = "发送支付验证码", httpMethod = "GET", response = RestResponse.class)
    public RestResponse sendPayCode(@ApiParam(value = "手机号") @RequestParam String phone,
                                    @ApiParam(value = "网关") @RequestParam String gateway,
                                    @ApiParam(value = "订单号") @RequestParam String orderNum) {
        return hlbQuickBusiness.sendPayCode(phone, orderNum, gateway);
    }

    @RequestMapping("/sendbindpaycode")
    @ApiOperation(value = "发送绑卡支付验证码", notes = "发送支付验证码", httpMethod = "GET", response = RestResponse.class)
    public RestResponse sendBindPayCode(@ApiParam(value = "手机号") @RequestParam String phone,
                                        @ApiParam(value = "网关") @RequestParam String gateway,
                                        @ApiParam(value = "绑卡号") @RequestParam String bindId,
                                        @ApiParam(value = "订单号") @RequestParam String orderNum) {
        return hlbQuickBusiness.bindCardPaySms(phone, gateway, bindId, orderNum);
    }

    @PostMapping(value = "/confirmpay")
    @ApiOperation(value = "完成支付", notes = "完成支付", httpMethod = "POST", response = RestResponse.class)
    public RestResponse confirmPay(@RequestBody ConfirmPayRequest request) {
        return hlbQuickBusiness.confirmPay(request);
    }

    @PostMapping(value = "/binddepositcard")
    @ApiOperation(value = "绑定结算银行卡", notes = "绑定结算银行卡", httpMethod = "POST", response = RestResponse.class)
    public RestResponse bindDepositCard(@RequestBody BindDepositCardRequest request) {
        return hlbQuickBusiness.bindDepositCard(request);
    }

    @PostMapping(value = "/deposit")
    @ApiOperation(value = "提现到结算银行卡", notes = "提现到结算银行卡", httpMethod = "POST", response = RestResponse.class)
    public RestResponse deposit(@RequestBody @Valid DepositRequest request, BindingResult result) {
        if (result.hasErrors())
            return RestResponse.build(RestResponse.AVS_ERROR_CODE, result.getFieldError().getDefaultMessage());
        return hlbQuickBusiness.deposit(request);
    }

    @PostMapping(value = "/hlbasyncpaynotify")
    @ApiOperation(value = "合利宝支付异步通知", notes = "支付异步通知", httpMethod = "POST", response = RestResponse.class)
    public String hlbAsyncPayNotify(AsyncPayNotifyRequest request) {
        return hlbQuickBusiness.hlbAsyncPayNotify(request);
    }

    @PostMapping(value = "/confirmpayms")
    @ApiOperation(value = "刷卡到立即到结算卡", notes = "刷卡到立即到结算卡", httpMethod = "POST", response = RestResponse.class)
    public RestResponse confirmPayMs(@RequestBody ConfirmPayMsRequest request) {
        return hlbQuickBusiness.confirmPayMs(request);
    }

}